import { v4 as uuid } from 'uuid'
export const FieldTypeMapping = Object.freeze({
    //字符串
    varchar: 'string',
    char: 'string',
    text: 'string',
    string: 'string',
    'character varying': 'string',

    number: 'number',
    numeric: 'number',
    bigint: 'number',
    smallint: 'number',
    float: 'number',
    double: 'number',
    decimal: 'number',
    int8: 'number',
    integer: 'number',

    time: 'date',
    timestamp: 'date',
    date: 'date',
    'timestamp without time zone': 'date',
    datetime: 'date',

    binary: 'binary',
    unknown: 'unknown',
})
export const normalizeFieldType = (fieldType: string) => {
    const lowerCaseType = fieldType?.toLowerCase()
    return FieldTypeMapping[lowerCaseType] || 'unknown'
}

export const randomUUID = () : string => {
    // let res
    // if ('randomUUID' in crypto) {
    //     res = crypto.randomUUID 
    // } else {
    //     res = uuid
    // }
    return uuid().replace(/-/g, '')
}